<?php
$categoria = $datosTubo['Tubo']['categoria_id'];
?>
<script type="text/javascript">
    //<![CDATA[
    $(document).ready(function() {
        var oTable = $('#grid').dataTable({
            "bJQueryUI": false,
            "bAutoWidth": false,
            "sPaginationType": "full_numbers",
            "sDom": '<"H"fl>t<"F"ip>',
            "aaSorting": [
                [0, "desc"]
            ]
        });

        $("tfoot input").keyup(function() { /* Filter on the column (the index) of this element */
            oTable.fnFilter(this.value, $("tfoot input").index(this));
        });

        /*
         * Support functions to provide a little bit of 'user friendlyness' to the textboxes in 
         * the footer
         */
//        $("tfoot input").each(function(i) {
//            asInitVals[i] = this.value;
//        });

        $("tfoot input").focus(function() {
            if (this.className == "search_init") {
                this.className = "";
                this.value = "";
            }
        });

        $("tfoot input").blur(function(i) {
            if (this.value == "") {
                this.className = "search_init";
                this.value = asInitVals[$("tfoot input").index(this)];
            }
        });

    });
    //]]>

</script>


<script type="text/javascript">
    jQuery(document).ready(function() {

        var sheepItForm = jQuery('#sheepItForm').sheepIt({
            separator: '',
            allowRemoveLast: true,
            allowRemoveCurrent: true,
            allowRemoveAll: true,
            allowAdd: true,
            allowAddN: true,
            maxFormsCount: 20,
            minFormsCount: 1,
            iniFormsCount: 1
        });

        var sheepItForm = jQuery('#sheepItFormC').sheepIt({
            separator: '',
            allowRemoveLast: true,
            allowRemoveCurrent: true,
            allowRemoveAll: true,
            allowAdd: true,
            allowAddN: true,
            maxFormsCount: 20,
            minFormsCount: 1,
            iniFormsCount: 1
        });

        var sheepItForm = jQuery('#sheepItFormV').sheepIt({
            separator: '',
            allowRemoveLast: true,
            allowRemoveCurrent: true,
            allowRemoveAll: true,
            allowAdd: true,
            allowAddN: true,
            maxFormsCount: 20,
            minFormsCount: 1,
            iniFormsCount: 1
        });

    });
</script>
<?php
$verificaCodigo = $datosTubo['Tubo']['categoria_id'];
switch ($verificaCodigo) {
    case 18:
        $nombrecategoria = 'DIVIDIR LIQUIDO';
        $sacar = 'SACAR LIQUIDO';
        $ver = 'VER LIQUIDOS PADRES';
        $vender = 'VENDER LIQUIDO';
        $ed = 'EDITAR DIVISION';
        $dividir = 'DIVIDIR LIQUIDO';
        $ingreso = 'INGRESAR LIQUIDO';
        $cortes = 'PADRES DEL LIQUIDO';
        $di = 'Division';
        break;
    case 19:
        $nombrecategoria = 'CORTAR BOBINA';
        $sacar = 'SACAR BOBINA';
        $ver = 'VER BOBINAS PADRES';
        $vender = 'VENDER BOBINA';
        $ed = 'EDITAR CORTE';
        $dividir = 'DIVIDIR BOBINA';
        $ingreso = 'INGRESAR BOBINA';
        $cortes = 'PADRES DE LA BOBINA';
        $di = 'Corte';
        break;
    case 20:
        $nombrecategoria = 'DIVIDIR PURPURINA';
        $sacar = 'SACAR PURPURINA';
        $ver = 'VER PURPURINAS PADRES';
        $vender = 'VENDER PURPURINA';
        $ed = 'EDITAR DIVISION';
        $dividir = 'DIVIDIR PURPURINA';
        $ingreso = 'INGRESAR PURPURINA';
        $cortes = 'PADRES DE LA PURPURINA';
        $di = 'Division';
        break;
}
?>
<?php foreach ($cortesTubo as $ct): ?>
    <style>
        #element_to_pop_up_vende_<?php echo $ct['Cortestubo']['id']; ?> { 
            background-color:#fff;
            box-shadow: 0px 2px 3px rgba(0, 0, 0, 0.298);
            border-radius:5px;
            color:#000;
            display:none; 
            padding:5px;
            min-width:300px;
            min-height: 180px;        
        }      
    </style>

    <style>
        #element_to_pop_up_saca_<?php echo $ct['Cortestubo']['id']; ?> { 
            background-color:#fff;
            box-shadow: 0px 2px 3px rgba(0, 0, 0, 0.298);
            border-radius:5px;
            color:#000;
            display:none; 
            padding:5px;
            min-width:300px;
            min-height: 180px;        
        }
        .b-close{
            cursor:pointer;
            position:absolute;
            right:10px;
            top:5px;            
        }   
    </style>

    <style>
        #element_to_pop_up_corta_<?php echo $ct['Cortestubo']['id']; ?> { 
            background-color:#fff;
            box-shadow: 0px 2px 3px rgba(0, 0, 0, 0.298);
            border-radius:5px;
            color:#000;
            display:none; 
            padding:5px;
            min-width:325px;
            min-height: 180px;        
        }
        .b-close{
            cursor:pointer;
            position:absolute;
            right:10px;
            top:5px;            
        }   
    </style>

    <style>
        #element_to_pop_up_arbol_<?php echo $ct['Cortestubo']['id']; ?> { 
            background-color:#fff;
            box-shadow: 0px 2px 3px rgba(0, 0, 0, 0.298);
            border-radius:5px;
            color:#000;
            display:none; 
            padding:5px;
            min-width:300px;
            min-height: 180px;        
        }
        .b-close{
            cursor:pointer;
            position:absolute;
            right:10px;
            top:5px;            
        }   
    </style>

    <div id="element_to_pop_up_vende_<?php echo $ct['Cortestubo']['id']; ?>">
        <a class="b-close">X</a>                    
        <div class="widget grid12">
            <div class="whead"><h6> <?php echo $vender ?> </h6><div class="clear"></div></div>
            &nbsp;
            <h4>&nbsp;&nbsp; PRODUCTO: <?php echo $ct['Cortestubo']['codigo']; ?></h4>
            <?php if ($idCategoria == 19): ?>
                <h5>&nbsp;&nbsp; Alto: <?php echo $ct['Cortestubo']['alto']; ?> cm. &nbsp;&nbsp; Peso: <?php echo $ct['Cortestubo']['peso']; ?> Kilos</h5>
            <?php else: ?>
                <h5>&nbsp;&nbsp; &nbsp;&nbsp; Peso: <?php echo $ct['Cortestubo']['peso']; ?> Kilos</h5>
            <?php endif; ?>
            <?php echo $this->Form->create('Cortestubos', array('action' => 'venderbobina', 'id' => "validate")); ?>
            <div class="formRow">                                                                                                                
                <div class="grid3"><label>Cliente:<span class="req">*</span></label></div>
                <div class="grid3">
                    <?php echo $this->Form->text('cliente', array('style' => 'width: 150px;', 'required')); ?>
                    <?php echo $this->Form->hidden('cortestubo_id', array('value' => $ct['Cortestubo']['id'])); ?>
                    <?php echo $this->Form->hidden('tubo_id', array('value' => $ct['Tubo']['id'])); ?>
                </div>
            </div>    
            <div class="formRow">                                                                                                                
                <div class="grid3"><label>Precio:<span class="req">*</span></label></div>
                <div class="grid3">
                    <?php echo $this->Form->text('precio', array('style' => 'width: 80px;', 'required')); ?>                    
                </div>
            </div>   
            <div class="formRow">                                                                                                                
                <div class="grid3"><label>Propietario:<span class="req">*</span></label></div>
                <div class="grid3">
                    <?php $dcp = array('Fernando' => 'FERNANDO', 'General' => 'GENERAL INTERNACIONAL SRL.'); ?>
                    <?php echo $this->Form->select('propietario', $dcp, array('required')); ?>                  
                </div>
            </div>
            <table style="width: 122px; border: 0;">
                <tr>
                    <td style="border: 0; text-align: center;"> Nota Entrega&nbsp;&nbsp; <?php
                        echo
                        $this->Form->checkbox('ne');
                        ?></td>
                </tr>
                <tr>
                    <td style="border: 0;text-align: center;"> Nota Venta&nbsp;&nbsp;&nbsp;<?php
                        echo
                        $this->Form->checkbox('nv');
                        ?></td>    
                </tr>
            </table>
            <div class="clear"></div>
            <div class="formRow">
                <input type="submit" value="Vender Bobina" class="buttonS bGreen" /><div class="clear"></div>            
            </div>
            </form>

        </div>
    </div>

    <div id="element_to_pop_up_saca_<?php echo $ct['Cortestubo']['id']; ?>">
        <a class="b-close">X</a>                    
        <div class="widget grid12">
            <div class="whead"><h6>SALIDA DE ALMACEN </h6><div class="clear"></div></div>
            &nbsp;
            <h4>&nbsp;&nbsp; PRODUCTO: <?php echo $ct['Cortestubo']['codigo']; ?></h4>
            <?php if ($idCategoria == 19): ?>
                <h5>&nbsp;&nbsp; Alto: <?php echo $ct['Cortestubo']['alto']; ?> cm. &nbsp;&nbsp Peso: <?php echo $ct['Cortestubo']['peso']; ?> Kilos</h5>
            <?php else: ?>
                <h5>&nbsp;&nbsp; &nbsp;&nbsp Peso: <?php echo $ct['Cortestubo']['peso']; ?> Kilos</h5>
            <?php endif; ?>
            <?php echo $this->Form->create('Cortestubos', array('action' => 'sacarbobina', 'id' => "validate")); ?>
            <div class="formRow">                                                                                                                
                <div class="grid3"><label>Enviar A:<span class="req">*</span></label></div>
                <div class="grid3">
                    <?php echo $this->Form->select('sucursale_id', $dcs, array('required')); ?>
                    <?php echo $this->Form->hidden('tubo_id', array('value' => $ct['Cortestubo']['id'])); ?>
                </div>
            </div>    
            <div class="clear"></div>
            <div class="formRow">
                <input type="submit" value="Registrar Salida" class="buttonS bGreen" /><div class="clear"></div>            
            </div>
            </form>
        </div>
    </div>

    <div id="element_to_pop_up_arbol_<?php echo $ct['Cortestubo']['id']; ?>">
        <a class="b-close">X</a>  
        <div class="widget grid12">
            <div class="whead"><h6><?php echo $cortes; ?> </h6><div class="clear"></div></div>
            <div class="content<?php echo $ct['Cortestubo']['id']; ?>"></div>        
        </div>
    </div>

    <div id="element_to_pop_up_corta_<?php echo $ct['Cortestubo']['id']; ?>">
        <a class="b-close">X</a>                    
        <div class="widget grid12">
            <div class="whead"><h6><?php echo $dividir; ?>                          
                </h6><div class="clear"></div></div>
            &nbsp;
            <h4>&nbsp;&nbsp; CODIGO PRODUCTO: <?php echo $ct['Cortestubo']['codigo']; ?></h4>
            <?php if ($categoria == 19): ?>
                <h5>&nbsp;&nbsp; Alto: <?php echo $ct['Cortestubo']['alto']; ?> cm. &nbsp;&nbsp Peso: <?php echo $ct['Cortestubo']['peso']; ?> Kilos</h5>
            <?php else: ?>
                <h5>&nbsp;&nbsp; &nbsp;&nbsp Peso: <?php echo $ct['Cortestubo']['peso']; ?> Kilos</h5>
            <?php endif; ?>

            <?php echo $this->Form->create('Cortestubo', array('action' => 'registrasubcortes', 'id' => "validate")); ?>      
            <div class="formRow">   
                <div style="float: left;"><?php echo $di; ?> # 1: =>&nbsp;&nbsp;</div>
                <?php if ($categoria == 19): ?>
                    <div class="grid3" style="float: left;"><label>Alto:<span class="req">*</span></label></div>
                    <div class="grid3" style="width: 60px; float: left;">
                        <?php echo $this->Form->text('0.alto', array('size' => 4, 'required')); ?>                       
                    </div>
                <?php endif; ?>
                &nbsp;&nbsp;&nbsp;&nbsp;
                <div class="grid3" style="float: left;"><label>&nbsp;Peso:<span class="req">*</span></label></div>
                <div class="grid3" style="width: 60px; float: left;">
                    <?php echo $this->Form->text('0.peso', array('size' => 4, 'required')); ?>                                    
                    <?php echo $this->Form->hidden('0.tubo_id', array('value' => $ct['Cortestubo']['id'])); ?>
                    <?php echo $this->Form->hidden('0.categoria', array('value' => $categoria)); ?>                                                    
                </div>
            </div>  
            <div class="clear"></div>

            <div class="formRow">   
                <div style="float: left;"><?php echo $di; ?> # 2: =>&nbsp;&nbsp;</div>
                <?php if ($categoria == 19): ?>
                    <div class="grid3" style="float: left;"><label>Alto:<span class="req">*</span></label></div>
                    <div class="grid3" style="width: 60px; float: left;">
                        <?php echo $this->Form->text('1.alto', array('size' => 4, 'required')); ?>                                    
                    </div>
                <?php endif; ?>
                &nbsp;&nbsp;&nbsp;&nbsp;
                <div class="grid3" style="float: left;"><label>&nbsp;Peso:<span class="req">*</span></label></div>
                <div class="grid3" style="width: 60px; float: left;">
                    <?php echo $this->Form->text('1.peso', array('size' => 4, 'required')); ?>     
                    <?php echo $this->Form->hidden('1.tubo_id', array('value' => $ct['Cortestubo']['id'])); ?>
                    <?php echo $this->Form->hidden('1.categoria', array('value' => $categoria)); ?>                                                    
                </div>
            </div>  
            <div class="clear"></div>

            <div class="formRow">   
                <div style="float: left;"><?php echo $di; ?> # 3: =>&nbsp;&nbsp;</div>
                <?php if ($categoria == 19): ?>
                    <div class="grid3" style="float: left;"><label>Alto:<span class="req">*</span></label></div>
                    <div class="grid3" style="width: 60px; float: left;">
                        <?php echo $this->Form->text('2.alto', array('size' => 4)); ?>                                    
                    </div>
                <?php endif; ?>
                &nbsp;&nbsp;&nbsp;&nbsp;
                <div class="grid3" style="float: left;"><label>&nbsp;Peso:<span class="req">*</span></label></div>
                <div class="grid3" style="width: 60px; float: left;">
                    <?php echo $this->Form->text('2.peso', array('size' => 4)); ?>    
                    <?php echo $this->Form->hidden('2.tubo_id', array('value' => $ct['Cortestubo']['id'])); ?>
                    <?php echo $this->Form->hidden('2.categoria', array('value' => $categoria)); ?>                                                    
                </div>
            </div>  
            <div class="clear"></div>
            <div class="formRow">
                <input type="submit" value="<?php echo $dividir; ?>" class="buttonS bGreen" /><div class="clear"></div>            
            </div>
            </form>
        </div>
    </div>   

<?php endforeach; ?>
<style>    
    /******* popup venta ***/
    #element_to_pop_up_venta{ 
        background-color:#fff;
        box-shadow: 0px 2px 3px rgba(0, 0, 0, 0.298);
        border-radius:5px;
        color:#000;
        display:none; 
        padding:5px;
        min-width:550px;
        min-height: 180px;        
    }   

    /******* popup salida ***/
    #element_to_pop_up{ 
        background-color:#fff;
        box-shadow: 0px 2px 3px rgba(0, 0, 0, 0.298);
        border-radius:5px;
        color:#000;
        display:none; 
        padding:5px;
        min-width:500px;
        min-height: 180px;        
    }
    .b-close{
        cursor:pointer;
        position:absolute;
        right:10px;
        top:5px;            
    } 
    /******* popup salida ***/
    #element_to_pop_up_corta{ 
        background-color:#fff;
        box-shadow: 0px 2px 3px rgba(0, 0, 0, 0.298);
        border-radius:5px;
        color:#000;
        display:none; 
        padding:5px;
        min-width:600px;
        min-height: 180px;        
    }    
</style>

<?php
$rol = $this->Session->read('Auth.User.role');
$sucursalUsuario = $this->Session->read('Auth.User.sucursale_id');
?>
<div class="grid12">
    <div class="widget">
        <div class="whead"><h6>Detalle del Producto</h6><div class="clear"></div></div>
        <div class="body">
            <table cellpadding="0" cellspacing="0" width="100%" class="tLight noBorderT">
                <tr>
                    <td><h4>Nombre</h4></td>
                    <td><h3><?php echo $datosTubo['Tubo']['nombre']; ?></h3></td>
                    <td><h4><?php echo $mic = ($categoria == 19) ? 'Micraje' : ''; ?></h4></td>
                    <td><h3><?php echo $mic = ($categoria == 19) ? $datosTubo['Tubo']['micraje'] : ''; ?></h3></td>                   
                </tr>
                <tr>
                    <td><h4>Peso</h4></td>
                    <td><h3><?php echo $datosTubo['Tubo']['peso']; ?> Kilos</h3></td>
                    <td><h4><?php echo $alto = ($categoria == 19) ? 'Alto' : ''; ?></h4></td>
                    <td colspan="3"><h3><?php echo $alto = ($categoria == 19) ? $datosTubo['Tubo']['alto'] . 'Centimetros' : ''; ?></h3>                
                </tr>
                <tr>
                    <td><h4>Cantidad Almacen <?php echo $this->Session->read('Auth.User.Sucursale.nombre'); ?></h4></td>
                    <td><h3>
                            <?php
                            if ($sucursalUsuario == 6) {
                                $cantidad = $tuboSinCortar['Movimientostubo']['cantidad'];
                                if (empty($cantidad)) {
                                    echo 'No tiene ';
                                } else {
                                    echo $cantidad;
                                }
                            } else {
                                echo $tubosEnterosSucursales;
                            }
                            ?> unidades
                        </h3></td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>                   
                </tr>
            </table> 
            <br />
            <?php
            $cantidad = $tuboSinCortar['Movimientostubo']['cantidad'];
            if (!empty($cantidad)):
                ?>
                <?php if ($rol == 'admin'): ?>
                    <div align="center">          
                        <a class="buttonS bRed" id="btSacaAlmacen">SACAR PRODUCTO</a>&nbsp;&nbsp;
                        <a class="buttonS bGreen" id="btVenderAlmacen">VENDER PRODUCTOS ENTEROS</a>&nbsp;&nbsp;
                        <a class="buttonS bBlue" id="btCorta">DIVIDIR PRODUCTO</a>&nbsp;&nbsp;
                        <!--                        <a class="buttonS bGreyish" id="btListado">LISTADO BOBINAS</a>&nbsp;&nbsp;-->
                    </div>
                <?php else: ?>

                <?php endif; ?>

            <?php else: ?>
                <div align="center">  
                    <!--                    <a class="buttonS bGreyish" id="btListado">LISTADO BOBINAS</a>&nbsp;&nbsp;-->
                </div>
            <?php endif; ?>
        </div>
    </div>
</div>

<!-- formulario salida -->

<div id="element_to_pop_up" style="display: none;">      
    <div class="grid12">
        <div class="widget">
            <h5>SACAR PRODUCTO: <?php echo $datosTubo['Tubo']['nombre']; ?></h5>
            <h6>
                Peso: <?php echo $datosTubo['Tubo']['peso']; ?> Kilos &nbsp;&nbsp; 
                <?php if ($categoria == 19): ?>
                    Alto: <?php echo $datosTubo['Tubo']['alto']; ?> Centimetros
                <?php else: ?>
                <?php endif; ?>
            </h6>
            <h6>Cantidad: <?php echo $tuboSinCortar['Movimientostubo']['cantidad']; ?> Unidades</h6>
            <a class="b-close">X</a>             
            <?php echo $this->Form->create('Movimientostubos', array('action' => 'registrarsalidas')); ?>            
            <div id="sheepItForm">

                <!-- Form template-->
                <div id="sheepItForm_template">

                    <table>
                        <tr>
                            <td><b>CODIGO DEL PRODUCTO # <span id="sheepItForm_label"></span>: &nbsp;&nbsp;</b></td>
                            <td>
                                <?php echo $this->Form->hidden(null, array('name' => 'data[Movimientostubos][#index#][categoria]', 'value' => $categoria)) ?>
                                <?php echo $this->Form->text(null, array('name' => "data[Movimientostubos][#index#][codigo]", 'required')); ?>
                                <?php echo $this->Form->hidden(null, array('name' => "data[Movimientostubos][#index#][tubo_id]", "value" => $tuboSinCortar['Tubo']['id'])); ?>
                                <?php echo $this->Form->select('Movimientostubos.#index#.sucursale_id', $dcs, array('required')); ?>
                            </td>                            
                            <td>
                                <a id="sheepItForm_remove_current">
                                    <b>&nbsp;&nbsp;X</b>
                                </a>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                &nbsp;
                            </td>
                        </tr>
                    </table>                      
                    <div class="clear"></div>                    
                </div>
                <!-- /Form template-->
                <div class="formRow">
                    <!-- No forms template -->
                    <div id="sheepItForm_noforms_template">Sin empleados</div>
                    <!-- /No forms template-->

                    <!-- Controls -->
                    <div id="sheepItForm_controls">
                        <div id="sheepItForm_add" class="btn form add"><a href="#" class="buttonS bGreen "><b>+</b> A&ntilde;adir mas Productos</a></div>
                        <div id="sheepItForm_remove_last" class="btn form remove"><a href="#" class="buttonS bRed "><b>-</b> Remover Producto</a></div>
                        <div id="sheepItForm_remove_all" class="btn form removeAll"><a href="#" class="buttonS bGold "><b>-</b> Remover Todos</a></div>

                        <div id="sheepItForm_add_n">
                            <input id="sheepItForm_add_n_input" type="text" size="4" style="width: 35px;" />
                            <div id="sheepItForm_add_n_button"><a><a href="#" class="buttonS bBlue"><b>+</b> A&ntilde;adir mas Productos</a></a></div></div>
                    </div>
                </div>
                <!-- /Controls -->
            </div>                      
            <input type="submit" value="Registrar Salidas" class="buttonM bBlack formSubmit"><div class="clear"></div>                        
            </form>            
        </div>
    </div>
</div>

<!-- fin formulario salida -->

<!-- formulario venta -->

<div id="element_to_pop_up_venta" style="display: none;">      
    <div class="grid12">
        <div class="widget">
            <h5>VENTA PRODUCTO: <?php echo $tuboSinCortar['Tubo']['nombre']; ?></h5>
            <h6>Peso: <?php echo $datosTubo['Tubo']['peso']; ?> Kilos &nbsp;&nbsp; 
                <?php if ($categoria == 19): ?>
                    Alto: <?php echo $datosTubo['Tubo']['alto']; ?> Centimetros
                <?php else: ?> 
                <?php endif; ?>            
            </h6>
            <h6>Cantidad: <?php echo $tuboSinCortar['Movimientostubo']['cantidad']; ?> Unidades</h6>
            <a class="b-close">X</a> 
            <?php echo $this->Form->create('Movimientostubos', array('action' => 'registraventas')); ?>
            <div id="sheepItFormV">

                <!-- Form template-->
                <div id="sheepItFormV_template">
                    <table>
                        <tr>
                            <td><b>PRODUCTO # <span id="sheepItFormV_label"></span>: &nbsp;&nbsp;</b></td>
                            <td>                                
                                Cliente
                                <?php echo $this->Form->text(null, array('name' => "data[Movimientostubos][#index#][cliente]", 'style' => "width: 120px;", 'required')); ?>
                                <?php echo $this->Form->hidden(null, array('name' => 'data[Movimientostubos][#index#][categoria]', 'value' => $categoria)) ?>
                                &nbsp;&nbsp;&nbsp;
                                Codigo
                                <?php echo $this->Form->text(null, array('name' => "data[Movimientostubos][#index#][codigo]", 'style' => "width: 125px;", 'required')); ?>
                                <?php echo $this->Form->hidden(null, array('name' => "data[Movimientostubos][#index#][tubo_id]", "value" => $tuboSinCortar['Tubo']['id'])); ?>
                                &nbsp;&nbsp;&nbsp;
                                Precio
                                <?php //echo $this->Form->text(null, array('name' => "data[Movimientostubos][#index#][precio]", 'style' => "width: 55px;", 'required'));    ?>
                                <input type="number" name="data[Movimientostubos][#index#][precio]" min="1" required id="data[Movimientostubos][#index#][precio]" style="width: 55px;" step="any" />
                                &nbsp;&nbsp;&nbsp;
                                Propietario
                                <?php $dcp = array('Fernando' => 'FERNANDO', 'General' => 'GENERAL INTERNACIONAL SRL.'); ?>
                                <?php echo $this->Form->select('Movimientostubos.#index#.propietario', $dcp, array('required')); ?>
                                &nbsp;&nbsp;
                                Nota Enrtrega:
                                <?php echo $this->Form->checkbox(null, array('name' => "data[Movimientostubos][#index#][ne]")); ?>
                                Nota Venta;
                                <?php echo $this->Form->checkbox(null, array('name' => "data[Movimientostubos][#index#][nv]")); ?>
                            </td>                            
                            <td>
                                <a id="sheepItFormV_remove_current">
                                    <b>&nbsp;&nbsp;X</b>
                                </a>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                &nbsp;
                            </td>
                        </tr>
                    </table>                                                                                            
                    <div class="clear"></div>                    
                </div>
                <!-- /Form template-->
                <div class="formRow">
                    <!-- No forms template -->
                    <div id="sheepItFormV_noforms_template">Sin empleados</div>
                    <!-- /No forms template-->

                    <!-- Controls -->
                    <div id="sheepItFormV_controls">
                        <div id="sheepItFormV_add" class="btn form add"><a href="#" class="buttonS bGreen "><b>+</b> A&ntilde;adir mas Proeductos</a></div>
                        <div id="sheepItFormV_remove_last" class="btn form remove"><a href="#" class="buttonS bRed "><b>-</b> Remover Producto</a></div>
                        <div id="sheepItFormV_remove_all" class="btn form removeAll"><a href="#" class="buttonS bGold "><b>-</b> Remover Todos</a></div>

                        <div id="sheepItFormV_add_n">
                            <input id="sheepItFormV_add_n_input" type="text" size="4" style="width: 35px;" />
                            <div id="sheepItFormV_add_n_button"><a><a href="#" class="buttonS bBlue"><b>+</b> A&ntilde;adir mas Producto</a></a></div></div>
                    </div>
                </div>
                <!-- /Controls -->
            </div>
            <input type="submit" value="Registrar Ventas" class="buttonM bBlack formSubmit"><div class="clear"></div>            
            </form>

        </div>
    </div>
</div>

<!-- fin formulario venta -->

<!-- formulario cortes -->

<div id="element_to_pop_up_corta" style="display: none;">      
    <div class="grid12">
        <div class="widget">
            <h5>DIVIDIR PRODUCTO: <?php echo $tuboSinCortar['Tubo']['nombre']; ?></h5>
            <h6>
                Peso: <?php echo $datosTubo['Tubo']['peso']; ?> Kilos &nbsp;&nbsp;                 
                <?php echo $mic = ($categoria == 19) ? 'Alto: ' . $datosTubo['Tubo']['alto'] . ' Centimetros' : ''; ?>
            </h6>
            <a class="b-close">X</a> 
            <?php echo $this->Form->create('Cortestubos', array('action' => 'registracortes')); ?>
            <?php //echo $this->Form->hidden('ca', array('value' => $categoria));   ?>
            <table>
                <tr>
                    <td><b>CODIGO DEL PRODUCTO <span id="sheepItFormC_label"></span>: &nbsp;&nbsp;</b></td>
                    <td>
                        <?php echo $this->Form->text(null, array('name' => "data[Tubo][codigo]", 'required')); ?>
                        <?php echo $this->Form->hidden(null, array('name' => "data[Tubo][tubo_id]", "value" => $tuboSinCortar['Tubo']['id'])); ?>
                        <?php echo $this->Form->hidden(null, array('name' => 'data[Tubo][categoria]', 'value' => $categoria)) ?>
                    </td>                                                
                </tr>

            </table>  

            <div id="sheepItFormC">

                <!-- Form template-->
                <div id="sheepItFormC_template">
                    <table>
                        <tr>
                            <td><b>CORTE # <span id="sheepItFormC_label"></span>: &nbsp;&nbsp;</b></td>

                            <?php if ($categoria == 19): ?>
                                <td><b>ALTO: &nbsp;&nbsp;</b></td>
                                <td>
                                    <?php //echo $this->Form->text(null, array('name' => "data[Cortestubos][#index#][alto]", 'required'));    ?>                                
                                    <input type="number" name="data[Cortestubos][#index#][alto]" min="1" required id="data[Cortestubos][#index#][alto]" style="width: 85px;" step="any" />                                    
                                </td>
                            <?php else: ?>
                            <?php endif; ?>
                            <td><b>&nbsp;&nbsp; PESO: &nbsp;&nbsp;</b></td>
                            <td>
                                <?php echo $this->Form->hidden(null, array('name' => 'data[Cortestubos][#index#][categoria]', 'value' => $categoria)) ?>
                                <?php //echo $this->Form->text(null, array('name' => "data[Cortestubos][#index#][peso]", 'required'));   ?>                                
                                <input type="number" name="data[Cortestubos][#index#][peso]" min="1" required id="data[Cortestubos][#index#][peso]" style="width: 85px;" step="any" />
                            </td>
                            <td>
                                <a id="sheepItFormC_remove_current">
                                    <b>&nbsp;&nbsp;X</b>
                                </a>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                &nbsp;
                            </td>
                        </tr>
                    </table>                                                                                            
                    <div class="clear"></div>                    
                </div>
                <!-- /Form template-->
                <div class="formRow">
                    <!-- No forms template -->
                    <div id="sheepItFormC_noforms_template">Sin Cortes</div>
                    <!-- /No forms template-->

                    <!-- Controls -->
                    <div id="sheepItFormC_controls">
                        <div id="sheepItFormC_add" class="btn form add"><a href="#" class="buttonS bGreen "><b>+</b> A&ntilde;adir mas <?php echo $di . 's' ?></a></div>
                        <div id="sheepItFormC_remove_last" class="btn form remove"><a href="#" class="buttonS bRed "><b>-</b> Remover <?php echo $di ?></a></div>
                        <div id="sheepItFormC_remove_all" class="btn form removeAll"><a href="#" class="buttonS bGold "><b>-</b> Remover Todos</a></div>

                        <div id="sheepItFormC_add_n">
                            <input id="sheepItFormC_add_n_input" type="text" size="4" style="width: 35px;" />
                            <div id="sheepItFormC_add_n_button"><a><a href="#" class="buttonS bBlue"><b>+</b> A&ntilde;adir mas <?php echo $di . 's' ?></a></a></div></div>
                    </div>
                </div>
                <!-- /Controls -->
            </div>

            <input type="submit" value="Registrar <?php echo $di . 's' ?>" class="buttonM bBlack formSubmit"><div class="clear"></div>            
            </form>

        </div>
    </div>
</div>
<!-- fin formulario salida -->

<!-- tabla bobinas cortadas -->
<div class="grid12">
    <div class="widget">
        <div class="whead"><h6>LISTADO DE PRODUCTOS DIVIDIDOS</h6><div class="clear"></div></div>
        <div class="shownpars">
            <?php
            App::import('Model', 'Cortestubo');
            $modeloCortes = new Cortestubo();

            App::import('Model', 'Movimientostrabajo');
            $modeloMovimientosTrabajo = new Movimientostrabajo();
            ?>            
            <table cellpadding="0" cellspacing="0" border="0" id="grid">
                <thead>
                    <tr>   
                        <th style="width: 20px;">ID</th>                         
                        <th style="width: 90px;">CODIGO NUEVO</th>  
                        <th>LUGAR</th>                        
                        <th style="width: 90px;">PADRE</th>                        
                        <?php if ($categoria == 19): ?>
                            <th>ALTO</th>          
                        <?php else: ?>
                        <?php endif; ?>
                        <th>PESO</th>
                        <th style="width: 130px;">Acciones</th>
                    </tr>
                </thead>

                <tfoot>
                    <tr>
                        <th rowspan="1" colspan="1">
                <div class="formRow">
                    <span class="grid6">
                        <input type="text" name="search_cantidad" placeholder="Codigo" class="search_init" style="width: 25px;" />
                    </span>
                </div>
                </th>
                <th rowspan="1" colspan="1">
                <div class="formRow">
                    <span class="grid6">
                        <input type="text" name="search_cantidad" placeholder="Codigo" class="search_init" style="width: 70px;" />
                    </span>
                </div>
                </th>
                <th rowspan="1" colspan="1">
                <div class="formRow">
                    <span class="grid6">
                        <input type="text" name="search_cantidad" placeholder="Lugar" class="search_init" />
                    </span>
                </div>
                </th>
                <th rowspan="1" colspan="1">
                <div class="formRow">
                    <span class="grid6">
                        <input type="text" name="search_cantidad" placeholder="Padre" class="search_init" style="width: 60px;" />
                    </span>
                </div>
                </th>
                <?php if ($categoria == 19): ?>
                    <th rowspan="1" colspan="1">
                    <div class="formRow">
                        <span class="grid6">
                            <input type="text" name="search_cantidad" placeholder="Alto" class="search_init" />
                        </span>
                    </div>
                    </th>
                <?php else: ?>
                <?php endif; ?>
                <th rowspan="1" colspan="1">
                <div class="formRow">
                    <span class="grid6">
                        <input type="text" name="search_alto" placeholder="Peso" class="search_init" />
                    </span>
                </div>
                </th>  
                <th rowspan="1" colspan="1">
                <div class="formRow">
                    <span class="grid6">
                        <input type="text" name="search_cantidad" placeholder="" class="search_init" />
                    </span>
                </div>
                </th>
                </tr>
                </tfoot>
                <tbody>
                    <?php //$i = 1;     ?>                
                    <?php foreach ($cortesTubo as $ct): ?>                       
                        <?php $idCodigo = $ct['Cortestubo']['id']; ?>
                        <tr>   
                            <td>
                                <?php echo $ct['Cortestubo']['id']; ?>                                
                            </td>
                           
                            <td>
                                <h3><?php echo $ct['Cortestubo']['codigo']; ?></h3>
                                <h6><?php echo $alto = ($categoria == 19) ? $ct['Tubo']['micraje'] . ' Micras' : ''; ?></h6>
                            </td>
                            <td>
                                <?php echo $ct['Sucursale']['nombre']; ?>                                
                            </td>
                            <td>
                                <?php
                                $padreNodo = $modeloCortes->getParentNode($ct['Cortestubo']['id']);
                                //echo "<b>" . $padreNodo['Cortestubo']['codigo'] . "</b>";
                                $codigoPadre = $padreNodo['Cortestubo']['codigo'];
                                if (empty($codigoPadre)) {
                                    echo $padreNodo['Cortestubo']['id'];
                                } else {
                                    echo $padreNodo['Cortestubo']['codigo'];
                                }
                                //debug($padreNodo);
                                ?>
                            </td> 
                            <?php if ($categoria == 19): ?>
                                <td><?php echo $ct['Cortestubo']['alto']; ?> cm.</td>
                            <?php else: ?>
                            <?php endif; ?>
                            <td>
                                <?php
                                //echo $ct['Cortestubo']['peso'];
                                $ultimoPeso = $modeloMovimientosTrabajo->find('first', array(
                                    'recursive' => -1,
                                    'conditions' => array('cortestubo_id' => $ct['Cortestubo']['id']),
                                    'order' => 'id DESC'
                                ));
                                //debug($ultimoPeso);
                                if (!empty($ultimoPeso)) {
                                    echo $ultimoPeso['Movimientostrabajo']['sobra'];
                                } else {
                                    echo $ct['Cortestubo']['peso'];
                                }
                                ?> Kilos
                            </td> 
                            <td>
                                <?php if ($rol == 'admin'): ?>
                                    <a onclick="ajaxSalida<?php echo $ct['Cortestubo']['id']; ?>();"><?php echo $this->Html->image("iconos/salida.png", array('title' => $sacar)) ?></a>

                                    <a onclick="ajaxCorta<?php echo $ct['Cortestubo']['id']; ?>();"><?php echo $this->Html->image("iconos/corte.png", array('title' => $nombrecategoria)) ?></a>

                                    <a onclick="ajaxArbol<?php echo $ct['Cortestubo']['id']; ?>();"><?php echo $this->Html->image("iconos/listaInv.png", array('title' => $ver)) ?></a>                            

                                    <a onclick="ajaxVende<?php echo $ct['Cortestubo']['id']; ?>();"><?php echo $this->Html->image("iconos/money.png", array('title' => $vender)) ?></a>
                                    <a href="<?php echo $this->Html->url(array('controller' => 'Cortestubos', 'action' => 'edit', $ct['Cortestubo']['id'])); ?>"><?php echo $this->Html->image('iconos/edit.png', array('title' => $ed)) ?></a>                                    
                                    <?php $codigoTubo = $ct['Cortestubo']['codigo']; ?>
                                    <?php
                                    echo $this->Form->postLink(
                                            $this->Html->image('iconos/baja2.png', array(
                                                "title" => 'Dar de Baja'
                                            )), array(
                                        'action' => 'darbaja',
                                        $ct['Cortestubo']['id']), array(
                                        'escape' => false,
                                        'confirm' => "Estas Seguro de dar baja a $codigoTubo?")
                                    );
                                    ?>
                                    <a href="<?php echo $this->Html->url(array('controller' => 'Cortestubos', 'action' => 'qr', $ct['Cortestubo']['id'])); ?>"><?php echo $this->Html->image('iconos/qr.png', array('title' => 'QR del producto')) ?></a>                                    
                                <?php else: ?>
                                <?php endif; ?>
                            </td>
                        </tr>                    
                    <?php endforeach; ?>               
                </tbody>               
            </table>
        </div> 
    </div> 
</div>
<!-- fin tabla bobinas cortadas -->

<script>
                                    $(document).ready(function() {
                                        // Binding a click event
                                        // From jQuery v.1.7.0 use .on() instead of .bind()
                                        $('#btSacaAlmacen').bind('click', function(e) {

                                            // Triggering bPopup when click event is fired
                                            $('#element_to_pop_up').bPopup({
                                                fadeSpeed: 'slow', //can be a string ('slow'/'fast') or int
                                                followSpeed: 1500, //can be a string ('slow'/'fast') or int 
                                                width: 20,
                                                position: ['auto', 40] //x, y
                                                        //$('#element_to_pop_up_<?php //echo $t['Tubo']['id'];                                           ?>').bPopup()
                                            });
                                        });

                                        $('#btListado').bind('click', function(e) {
                                            //console.log('muestra enteras');
                                            $('#listadoEnteras').toggle('slow');
                                        });

                                        //venta bobinas
                                        $('#btVenderAlmacen').bind('click', function(e) {

                                            // Triggering bPopup when click event is fired
                                            $('#element_to_pop_up_venta').bPopup({
                                                fadeSpeed: 'slow', //can be a string ('slow'/'fast') or int
                                                followSpeed: 1500, //can be a string ('slow'/'fast') or int 
                                                width: 20,
                                                position: ['auto', 40] //x, y
                                                        //$('#element_to_pop_up_<?php //echo $t['Tubo']['id'];                                           ?>').bPopup()
                                            });
                                        });
                                        //fin venta bobinas

                                        $('#btCorta').bind('click', function(e) {

                                            // Triggering bPopup when click event is fired
                                            $('#element_to_pop_up_corta').bPopup({
                                                fadeSpeed: 'slow', //can be a string ('slow'/'fast') or int
                                                followSpeed: 1500, //can be a string ('slow'/'fast') or int 
                                                width: 20,
                                                position: ['auto', 40] //x, y
                                                        //$('#element_to_pop_up_<?php //echo $t['Tubo']['id'];                                           ?>').bPopup()
                                            });
                                        });

                                    });
</script>

<?php foreach ($cortesTubo as $ct): ?>
    <script>

        function ajaxVende<?php echo $ct['Cortestubo']['id']; ?>()
        {
            // Binding a click event
            // From jQuery v.1.7.0 use .on() instead of .bind()
            //$('#btAjaxGeneraSalida_<?php //echo $ct['Cortestubo']['id'];             ?>').bind('click', function(e) {
            console.log('click');
            // Triggering bPopup when click event is fired
            $('#element_to_pop_up_vende_<?php echo $ct['Cortestubo']['id']; ?>').bPopup({
                fadeSpeed: 'slow', //can be a string ('slow'/'fast') or int
                followSpeed: 1500, //can be a string ('slow'/'fast') or int                                             
                //$('#element_to_pop_up_<?php //echo $t['Tubo']['id'];                     ?>').bPopup()
            });
            //});    
        }

        function ajaxSalida<?php echo $ct['Cortestubo']['id']; ?>()
        {
            // Binding a click event
            // From jQuery v.1.7.0 use .on() instead of .bind()
            //$('#btAjaxGeneraSalida_<?php //echo $ct['Cortestubo']['id'];             ?>').bind('click', function(e) {
            console.log('click');
            // Triggering bPopup when click event is fired
            $('#element_to_pop_up_saca_<?php echo $ct['Cortestubo']['id']; ?>').bPopup({
                fadeSpeed: 'slow', //can be a string ('slow'/'fast') or int
                followSpeed: 1500, //can be a string ('slow'/'fast') or int                                             
                //$('#element_to_pop_up_<?php //echo $t['Tubo']['id'];                     ?>').bPopup()
            });
            //});    
        }

        function ajaxCorta<?php echo $ct['Cortestubo']['id']; ?>()
        {
            // Triggering bPopup when click event is fired
            $('#element_to_pop_up_corta_<?php echo $ct['Cortestubo']['id']; ?>').bPopup({
                fadeSpeed: 'slow', //can be a string ('slow'/'fast') or int
                followSpeed: 1500, //can be a string ('slow'/'fast') or int                                             
                //$('#element_to_pop_up_<?php //echo $t['Tubo']['id'];                    ?>').bPopup()
            });
        }

        function ajaxArbol<?php echo $ct['Cortestubo']['id']; ?>()
        {
            $('#element_to_pop_up_arbol_<?php echo $ct['Cortestubo']['id']; ?>').bPopup({
                fadeSpeed: 'slow', //can be a string ('slow'/'fast') or int
                followSpeed: 1500, //can be a string ('slow'/'fast') or int                                            
                contentContainer: '.content<?php echo $ct['Cortestubo']['id']; ?>',
                loadUrl: "<?php echo $this->Html->url(array('controller' => 'Cortestubos', 'action' => 'ajaxverarbol', $ct['Cortestubo']['id'])); ?>", //Uses jQuery.load()                                            
            });
        }

    </script>

<?php endforeach; ?> 